# coding=utf-8
__author__ = 'Administrator'
from django.test import TestCase
import wmi
import os


def get_cpu_info():
    c = wmi.WMI()
    # CPU类型和内存
    for processor in c.Win32_Processor():
        # print "Processor ID: %s" % processor.DeviceID
        print("Process Name: %s" % processor.Name.strip())
    for Memory in c.Win32_PhysicalMemory():
        print("Memory Capacity: %.fMB" % (int(Memory.Capacity)/1048576))

def disk():
    c = wmi.WMI()
    # 获取硬盘分区
    for physical_disk in c.Win32_DiskDrive ():
        for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
            for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
                print(physical_disk.Caption.encode("UTF8"), partition.Caption.encode("UTF8"), logical_disk.Caption)

    # 获取硬盘使用百分情况
    for disk in c.Win32_LogicalDisk(DriveType=3):
        print(disk.Caption, "%0.2f%% free" % (100.0 * float(disk.FreeSpace) / float(disk.Size)))



if __name__ == "__main__":
    get_cpu_info()
    disk()